<template>
  <div class="header">
    <div class="logo">个人博客系统</div>
    <el-menu
      mode="horizontal"
      router
      :default-active="route.path"
    >
      <el-menu-item index="/">首页</el-menu-item>
      <el-menu-item index="/article/list">文章列表</el-menu-item>
      <el-menu-item index="/about">关于</el-menu-item>
      <el-menu-item index="/chat">AI 助手</el-menu-item>
    </el-menu>
    <div class="user-info">
      <template v-if="!userStore.isLoggedIn">
        <el-button type="primary" @click="$router.push('/login')">登录</el-button>
        <el-button @click="$router.push('/register')">注册</el-button>
      </template>
      <template v-else>
        <el-dropdown>
          <span class="el-dropdown-link">
            {{ userStore.userInfo.nickname }}<el-icon class="el-icon--right"><arrow-down /></el-icon>
          </span>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item @click="$router.push('/user/profile')">个人中心</el-dropdown-item>
              <el-dropdown-item @click="handleLogout">退出登录</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
      </template>
    </div>
  </div>
</template>

<script setup>
import { useRoute } from 'vue-router'
import { useUserStore } from '../store/modules/user'

const route = useRoute()
const userStore = useUserStore()

const handleLogout = () => {
  userStore.logout()
}
</script>

<style scoped>
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 20px;
  font-weight: bold;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
</style> 